#include "StdAfx.h"
#include <wx/xrc/xmlres.h>
#include <wx/collpane.h>
#include <wx/aui/aui.h>
#include "TerrainDirector.hpp"
#include "ControlPanel.hpp"

namespace he
{
	BEGIN_EVENT_TABLE(ControlPanel, wxPanel)
		EVT_TEXT(XRCID("ID_TERRAIN_RADIUS"), ControlPanel::on_terrain_tile_size)
	END_EVENT_TABLE()

	ControlPanel::ControlPanel(wxWindow *pParent, TerrainDirector &Director)
		: wxPanel(pParent), m_TerrainDirector(Director)
	{
		// Create default sizer
		wxBoxSizer *p_sizer = new wxBoxSizer(wxHORIZONTAL);
		// Create the collapsible panel for terrain
		wxCollapsiblePane *p_panel_terrain = new wxCollapsiblePane(this, wxID_ANY,
			wxT("Terrain"), wxDefaultPosition, wxDefaultSize,
			wxCP_NO_TLW_RESIZE | wxBORDER_NONE | wxCP_DEFAULT_STYLE);
		p_sizer->Add(p_panel_terrain, wxSizerFlags(1).Border(wxALL, 5).Expand());
		// Get the main panel
		wxWindow *p_panel_parent = p_panel_terrain->GetPane();
		{
			wxBoxSizer *p_child_sizer = new wxBoxSizer(wxVERTICAL);
			wxPanel *p_main_panel =  wxXmlResource::Get()->LoadPanel(p_panel_parent,
				wxT("ID_CONTROL_MAIN_PANEL"));
			p_child_sizer->Add(p_main_panel, wxSizerFlags(1).Border(wxALL, 5).Expand());
			p_panel_parent->SetSizer(p_child_sizer);
			// Get the notebook
			wxNotebook *p_notebook = XRCCTRL(*p_main_panel, "ID_CONTROL_NOTEBOOK",
				wxNotebook);
			// Get the terrain main panel and add it to neotebook
			wxPanel *p_terrain_panel =  wxXmlResource::Get()->LoadPanel(p_notebook,
				wxT("ID_TERRAIN_SIZE_PANEL"));
			p_notebook->AddPage(p_terrain_panel, wxT("Details"));
		}
		// Set the main sizer
		SetSizer(p_sizer);
		Layout();
	}

	void ControlPanel::on_terrain_tile_size(wxCommandEvent &Event)
	{
		long value;
		Event.GetString().ToLong(&value);
		// Signal the event
		m_TerrainDirector.signal_tile_size(value);
	}
}